//
//  CustomTableViewCell.m
//  UI11_homework_Movielist
//
//  Created by aaaaaa on 16/6/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomTableViewCell.h"
#import "Movie.h"

#define kHeight self.contentView.frame.size.height
#define kWidth self.contentView.frame.size.width

@interface CustomTableViewCell ()

@property (nonatomic, retain) UIImageView *movieImageView;
@property (nonatomic, retain) UILabel *nameLable;
@property (nonatomic, retain) UILabel *idLable;

@end

@implementation CustomTableViewCell

- (void)dealloc
{
    [_movie release];
    [_movieImageView release];
    [_nameLable release];
    [_idLable release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        _movieImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_movieImageView];
        [_movieImageView release];
        
        _nameLable = [[UILabel alloc] init];
        [self.contentView addSubview:_nameLable];
        [_nameLable release];
        
        _idLable = [[UILabel alloc] init];
        [self.contentView addSubview:_idLable];
        [_idLable release];
    }
    
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    
    
    self.movieImageView.frame = CGRectMake(10, 10, kWidth * 0.3, kHeight - 20);
//    self.movieImageView.backgroundColor = [UIColor orangeColor];
    
    self.nameLable.frame = CGRectMake(_movieImageView.frame.size.width + 40, 20, kWidth * 0.55, kHeight * 0.3);
//    self.nameLable.backgroundColor = [UIColor grayColor];
    
    self.idLable.frame = CGRectMake(_movieImageView.frame.size.width + 40, kHeight * 0.3 + 40, kWidth * 0.55, kHeight * 0.3);
//    self.idLable.backgroundColor = [UIColor lightGrayColor];
}


- (void)setMovie:(Movie *)movie{
    if (_movie != movie) {
        [_movie release];
        _movie = [movie retain];
    }
    
    self.nameLable.text = movie.movieName;
    self.idLable.text = movie.movieId;
    
    NSURL *url = [NSURL URLWithString:movie.pic_url];
    NSData *data = [NSData dataWithContentsOfURL:url];
    self.movieImageView.image = [UIImage imageWithData:data];
}




















@end
